<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

</head>
<body>
<div id="v-div" class="container">
    <h1 class="text-center">微博首页</h1>
    <div v-if="user==null" class="pull-right">
        <a class="btn btn-default" href="/reg.html">注册</a>
        <a class="btn btn-default" href="/login.html">登录</a>
    </div>
    <div v-if="user!=null" class="pull-right">
        <span>欢迎{{user.nick}}!</span>
        <a href="#" @click="logout()">退出登录</a><br>
        <a href="/myweibo.html">我的微博</a>
        <hr>
        <a class="btn btn-default" href="/send.html">发布微博</a>
    </div>
    <hr>
    <div v-for="weibo in arr">
        <p>{{weibo.author}}说:{{weibo.content}}</p>
        <img class="img-responsive" :src="weibo.url">
    </div>
</div>
<!--引入axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!--引入vue框架-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    let v = new Vue({
        el:"#v-div",
        data:{
            user:null,
            arr:[]
        },
        created:function () {
            //发送请求询问是否登录过 并获取点前登录用户信息
            axios.get("/checkLogin").then(function (response) {
                v.user = response.data==""?null:response.data;
            })
            axios.get("/select").then(function (response) {
                v.arr = response.data;
            })
        },
        methods:{
            logout:function () {
                axios.get("/logout").then(function () {
                    location.reload();//刷新页面
                })
            }
        }
    })
</script>
</body>
</html>